package com.childmiles.gwt.client.ui.awards;

import com.childmiles.gwt.client.domain.AwardWinner;
import com.childmiles.gwt.client.ui.AwardPanel;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class AwardsView extends Composite implements AwardsPresenter.Display {
    interface AwardsViewUiBinder extends UiBinder<Widget, AwardsView> {
    }
    private static AwardsViewUiBinder uiBinder = GWT.create(AwardsViewUiBinder.class);

    @UiField
    Label awardWinnerNameLabel;
    @UiField
    FlexTable awardsTable;

    public AwardsView() {
        initWidget(uiBinder.createAndBindUi(this));
        
    }

    private void populateAwardsTable(AwardWinner awardWinner) {
        awardsTable.setSize("600px","500px");
        Image awardWinnerPhoto = new Image(awardWinner.getPhotoUrl());
        awardWinnerPhoto.setTitle("Click for preferences");
        awardWinnerPhoto.addStyleName("awardWinnerImage");
        // 4 X 2 fixed grid
        awardsTable.setWidget(0,0,awardWinnerPhoto);
        awardsTable.setWidget(0,1,new AwardPanel(1, awardWinner.getAwards().get(1)));
        awardsTable.setWidget(0,2,new AwardPanel(2, awardWinner.getAwards().get(2)));
        awardsTable.setWidget(0,3,new AwardPanel(3, awardWinner.getAwards().get(3)));
        awardsTable.setWidget(1,0,new AwardPanel(4, awardWinner.getAwards().get(4)));
        awardsTable.setWidget(1,1,new AwardPanel(5, awardWinner.getAwards().get(5)));
        awardsTable.setWidget(1,2,new AwardPanel(6, awardWinner.getAwards().get(6)));
        awardsTable.setWidget(1,3,new AwardPanel(7, awardWinner.getAwards().get(7)));
    }

    public Widget asWidget() {
        return this;
    }
    
    public void setAwardWinner(AwardWinner awardWinner) {
        populateAwardsTable(awardWinner);
    }
    
    public FlexTable.Cell getCellForEvent(ClickEvent event) {
        return awardsTable.getCellForEvent(event);
    }

    public HasText getAwardWinnerNameLabel() {
        return awardWinnerNameLabel;
    }
//
//    public HasKeyDownHandlers getAwardWinnerNameTextBoxForKeyDownHandler() {
//        // TODO Auto-generated method stub
//        return awardWinnerNameTextBox;
//    }
//
//    public HasClickHandlers getOkButton() {
//        return okButton;
//    }

    public FlexTable getAwardsTable() {
        // TODO Auto-generated method stub
        return awardsTable;
    }

}
